package config

import (
	"gopkg.in/ini.v1"
	"os"
	"path/filepath"
)

var (
	// AppConfig is the instance of Config, store the config information from file
	AppConfig     *ini.File
	AppPath       string
	appConfigPath string
)

func init() {

	var err error
	if AppPath, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil {
		panic(err)
	}
	workPath, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	var filename = "config.ini"
	if os.Getenv("RUNMODE") != "" {
		filename = os.Getenv("RUNMODE") + "dev.config.ini"
	}

	appConfigPath = filepath.Join(workPath, "config", filename)

	cfg, err := ini.Load(appConfigPath)
	if err != nil {
		panic(err)
	}

	AppConfig = cfg
}
